<?php

/**
 * Sen an email
 * 
 * @param String $to
 * @param String $subject
 * @param String $body
 * @param String $alt_body [opcional]
 */
function blg_send_email($to, $subject, $body, $alt_body=''){	
	$mail             = new PHPMailer();
	
	//GMail settings
	$mail->IsSMTP();
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
	$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
	$mail->Port       = 465;                   // set the SMTP port	
	$mail->Username   = blg_get_config('phpmailer_user');	// GMAIL username
	$mail->Password   = blg_get_config('phpmailer_pass');	// GMAIL password
	
	//Headers
	$mail->SetFrom(blg_get_config('phpmailer_reply_email'),blg_get_config('phpmailer_reply_name'));
	$mail->AddReplyTo(blg_get_config('phpmailer_reply_email'), blg_get_config('phpmailer_reply_name'));	
	$mail->AddAddress($to);	
	
	//Body
	$mail->Subject	= $subject;	
	$mail->AltBody	= $alt_body; //Text Body
	$mail->WordWrap	= 50; //set word wrap		
	$mail->MsgHTML($body);
	
	$mail->IsHTML(true); // send as HTML
	
	if(!$mail->Send()) {
		echo $mail->ErrorInfo;
		return FALSE;
	} else {
		return TRUE;
	}	
}